﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using YmtSystem.Infrastructure.EventBusService;

namespace YmtAuth.Domain.EventHistory
{
    public class YmtUserPasswordChangeEvent : Entity<string>, IEvent
    {
        [BsonIgnoreIfNull]
        [BsonElement("lId")]
        public string LoginId { get; set; }

        [BsonIgnoreIfNull]
        [BsonElement("uId")]
        public int UserId { get; set; }

        [BsonIgnoreIfNull]
        [BsonElement("cIp")]
        public string ClientIp { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("oPas")]
        public string OldPassword { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("nPas")]
        public string NewPassword { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("cType")]
        public string ClientType { get; set; }
        [BsonElement("mTime")]
        public DateTime ModifyTime { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("pType")]
        public string PasswordType { get; set; }

        public YmtUserPasswordChangeEvent(int userId, string loginId, string oldPassword, string newPassword, string clientIp = null, string clientType = null, string pasType = null)
        {
            this.UserId = userId;
            
            this.Id = ObjectId.GenerateNewId().ToString();
            this.LoginId = loginId;
            this.ClientIp = clientIp;
            this.OldPassword = oldPassword;
            this.NewPassword = newPassword;
            this.ClientType = clientType;
            this.ModifyTime = DateTime.Now;
            this.PasswordType = pasType;
        }

        protected YmtUserPasswordChangeEvent()
        {
        }

        protected override IEnumerable<object> CompareValues()
        {
            yield return this.Id;
        }
    }
}
